package br.com.spam.pipeline;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

public class ReaderHelper
{

	public static String[] getCodeAt(String path, String errorMessage)
	{
		try
		{
			String[] data = readFileAt(path);
			List<String> dataList = new ArrayList<String>();
			for (int i = 0; i < data.length; i++)
				dataList.add(data[i]);
			return dataList.toArray(new String[0]);
		}
		catch (IOException ex)
		{
			JOptionPane.showMessageDialog(null, errorMessage);
		}
		return null;
	}

	private static String[] readFileAt(String path) throws IOException
	{
		BufferedReader in = new BufferedReader(new FileReader(path));
		String data = "";
		while (in.ready())
			data += in.readLine() + "\n";
		return data.split("\n");
	}

}
